package com.newworld.dmsapp2.activity;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Paint;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.newworld.dmsapp2.BaseActivity;
import com.newworld.dmsapp2.DemoReceiver;
import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.activity.designtask.AssignAndReassignTaskActivity;
import com.newworld.dmsapp2.activity.serviceapply.ViewPagerActivity;
import com.newworld.dmsapp2.bean.Task;
import com.newworld.dmsapp2.bean.User;
import com.newworld.dmsapp2.ui.view.CustomDialog;
import com.newworld.dmsapp2.ui.view.CustomLoadingDialog;
import com.newworld.dmsapp2.util.Config;
import com.newworld.dmsapp2.util.HttpUtil;
import com.newworld.dmsapp2.util.SingleSample;
import com.newworld.dmsapp2.util.Tool;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class ServiceScheduleActivity extends BaseActivity implements
		OnClickListener {
	private TextView sch_assign_tasknum, sch_assign_address, sch_assign_object,
			sch_assign_assigntime, sch_assign_expectedtime,sch_assign_reporter,sch_assign_reporterphone,
			sch_assign_reminder, sch_assign_serviceman, sch_assign_telephone,
			sch_recordtime, sch_assign_describe, tx_assign, titleView,
			servicechedule_timeTv;
	private Button btn_accept_repair, btn_start_repair, btn_goon_repair,
			btn_apply_change;
	private ImageView assign_repair_voice, assign_repair_image1,
			assign_repair_image2;
	private LinearLayout leftlayout;
	private LinearLayout repairePersonLn, guideTimelinelv;
	private ProgressBar loginbar;
	private CustomLoadingDialog uploadingdialog;
	private View assignLineView;

	private ImageView assignIv;

	private Intent intent;

	private Bundle bundle;

	private String message = "";
	
	private User user;
	private Task task;
	private String realfunctioncode;
	private String functioncode;
	private String taskstate;
	private String areaname = "";
	private Boolean canClick = false;
	private boolean sureFlag = false;
	private String statusTypeCode;
	private String sessionId;
	private String repairId = "";
	private String houseFullName;
	private String peopleType;
	private boolean isReporter = false;

	Handler mHandler = new Handler() {
		@SuppressLint("NewApi")
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			Bundle b = new Bundle();
			Intent i = new Intent();
			switch (msg.what) {
			case Config.HANDLER_MSG_SUCCESS:

				sch_assign_tasknum.setText(task.getRepairNum());
				sch_assign_address.setText(houseFullName);
				hideOrShowViews();
				// 维修区域信息拼接
				/*if (task.getHouse_houseType_typeCode() != null) {
					if (task.getHouse_houseType_typeCode().equals(
							Config.AREACODE_OUTDOOR)) {
						areaname = Config.AREANAME_PUBLIC;
					} else {
						areaname = Config.AREANAME_INDOOR;
					}
				}*/
				areaname = Tool.getHouseType(task);
				sch_assign_object.setText(areaname + "/"
						+ task.getRepairObject());
				if (taskstate.equals(Config.TASKSTATE_DISTRIBUTE)
						|| taskstate.equals(Config.TASKSTATE_TORECEIVEORDER)
						|| taskstate.equals(Config.TASKSTATE_TOPOST)
						|| taskstate.equals(Config.TASKSTATE_BEASKED)
						) {// 分配
					if (null != task.getDispatchTime()) {
						if (task.getDispatchTime().length() > Config.TIMELENGTH) {
							sch_assign_assigntime.setText(task
									.getDispatchTime().substring(0,
											Config.TIMELENGTH));
						} else {
							sch_assign_assigntime.setText(task
									.getDispatchTime());
						}
					}
					servicechedule_timeTv.setText("分配时间：");
				} else if (taskstate.equals(Config.TASKSTATE_GETTASK)) {// 受理
					if (null != task.getReportTime()) {
						if (task.getReportTime().length() > Config.TIMELENGTH) {
							sch_assign_assigntime.setText(task.getReportTime()
									.substring(0, Config.TIMELENGTH));
						} else {
							sch_assign_assigntime.setText(task.getReportTime());
						}
					}
					servicechedule_timeTv.setText("报修时间：");
				}
				if (null != task.getExpectTime()) {
					if (task.getExpectTime().length() > Config.TIMELENGTH) {
						sch_assign_expectedtime.setText(task.getExpectTime()
								.substring(0, Config.TIMELENGTH));
					} else {
						sch_assign_expectedtime.setText(task.getExpectTime());
					}
				}
				sch_assign_reporter.setText(task.getReporter_realName());
				sch_assign_reporterphone.setText(task.getReporter_phone());
				sch_assign_reporterphone.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View view) {
						// TODO Auto-generated method stub
						intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
								+ sch_assign_reporterphone.getText().toString()));
						startActivity(intent);
					}
				});
				
				sch_assign_serviceman.setText(task.getServer_realName());
				sch_assign_telephone.setText(task.getServer_mobilePhone());
				sch_assign_describe.setText(task.getProblemDescript());
				if (null != task.getProblemImage1()
						&& !task.getProblemImage1().equals("")) {
					assign_repair_image1.setVisibility(View.VISIBLE);
					ImageLoader.getInstance().displayImage(
							"file://" + Config.IMAGE_PATH
									+ task.getProblemImage1(),
							assign_repair_image1, options);
				} else {
					assign_repair_image2.setVisibility(View.INVISIBLE);
				}
				if (null != task.getProblemImage2()
						&& !task.getProblemImage2().equals("")) {
					assign_repair_image2.setVisibility(View.VISIBLE);
					ImageLoader.getInstance().displayImage(
							"file://" + Config.IMAGE_PATH
									+ task.getProblemImage2(),
							assign_repair_image2, options);
				} else {
					assign_repair_image2.setVisibility(View.INVISIBLE);
				}
				if (null != task.getProblemVoice()
						&& !task.getProblemVoice().equals("")) {
					int voicetime = Tool.voiceTime(ServiceScheduleActivity.this,Config.VOICE_PATH+task.getProblemVoice());
					
					int realvoicetime = (int) voicetime/1000;
					//assign_repair_voice.setVisibility(View.VISIBLE);
					Log.e("realvoicetime", realvoicetime+"'");
					
					assign_repair_voice.setVisibility(View.VISIBLE);
					sch_recordtime.setVisibility(View.VISIBLE);
					sch_recordtime.setText(realvoicetime+"'");
				} else {
					assign_repair_voice.setVisibility(View.INVISIBLE);
					sch_recordtime.setVisibility(View.INVISIBLE);
				}
				canClick = true;
				Toast.makeText(ServiceScheduleActivity.this, (String) msg.obj,
						Toast.LENGTH_SHORT);
				loginbar.setVisibility(View.INVISIBLE);
				break;

			case Config.HANDLER_MSG_FAIL_1:
				Tool.judgedialog(ServiceScheduleActivity.this,"json连接失败",uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_FAIL_2:
				Tool.judgedialog(ServiceScheduleActivity.this,"json解析数据错误",uploadingdialog, loginbar);
				break;

			case Config.HANDLER_MSG_REPAIR_ACCEPT_SUCCESS:
				sureFlag = true;
				System.out.println("task.getStatusType_typeCode()--->3"
						+ task.getStatusType_typeCode());
				System.out.println("taskstate---》" + task.getTaskState());
				Tool.judgedialog(ServiceScheduleActivity.this,"接单成功",uploadingdialog, loginbar);
				System.out.println("接单成功oooooooooooooooooooo");
				btn_accept_repair.setBackground(getResources().getDrawable(
						R.drawable.button_blue_press));
				btn_accept_repair.setEnabled(false);
				btn_start_repair.setBackground(getResources().getDrawable(
						R.drawable.button_blue));
				btn_start_repair.setEnabled(true);
				taskstate = Config.TASKSTATE_TODO;
				System.out.println("接单成功11111111111111111111");
				break;

			case Config.HANDLER_MSG_REPAIR_START_SUCCESS:
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				b.putString(Config.FUNCTIONCODE, functioncode);
				b.putString(Config.TASKSTATE, taskstate);
				b.putString(Config.HOUSEFULLNAME, houseFullName);
				b.putString(Config.PEOPLETYPE, peopleType);
				b.putString(Config.REPAIRID, repairId);
				i = new Intent(ServiceScheduleActivity.this,
						ServiceScheduleAccomplishActivity.class);
				i.putExtras(b);
				startActivity(i);
				finish();
				break;
			case Config.HANDLER_MSG_REPAIR_START_FAIL_1:
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				break;

			case Config.HANDLER_MSG_REPAIR_REDISPATCH_SUCCESS:
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				if(user.isTaskExistByRepairId(repairId)){
					if(user.deleteTaskByRepairId(repairId)){
						Log.e("申请改派删除任务", repairId + "删除成功");
					}else{
						Log.e("申请改派删除任务", repairId + "删除失败");
					}
					
				}
				finish();
				break;
			case Config.HANDLER_MSG_GOING:
				message = (String) msg.obj;
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_REDISPATCH_FAIL_1:
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_REDISPATCH_FAIL_2:
				Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				break;
			case Config.HANDLER_MSG_REPAIR_REDISPATCH_FAIL_3:
				Toast.makeText(ServiceScheduleActivity.this, (String) msg.obj,
						Toast.LENGTH_SHORT);
				break;
			case Config.HANDLER_MSG_FAIL:
				message = (String) msg.obj;
				if (uploadingdialog != null) {
					Tool.judgedialog(ServiceScheduleActivity.this,(String) msg.obj,uploadingdialog, loginbar);
				}
				loginbar.setVisibility(View.INVISIBLE);
				Toast.makeText(ServiceScheduleActivity.this, message,
						Toast.LENGTH_SHORT).show();
				break;
			case Config.HANDLER_MSG_GETTASK_FAIL:
				if (uploadingdialog != null) {
					if (uploadingdialog.isShowing()) {
						uploadingdialog.dismiss();
					} else {
						uploadingdialog.show();
					}
				}
				loginbar.setVisibility(android.view.View.INVISIBLE);
				
				new AlertDialog.Builder(ServiceScheduleActivity.this)
						.setTitle("提醒")
						.setMessage((String) msg.obj)
						.setPositiveButton(
								"取消",
								new android.content.DialogInterface.OnClickListener() {

									@Override
									public void onClick(DialogInterface arg0,
											int arg1) {
										// TODO Auto-generated method stub
										if(user.isTaskExistByRepairId(repairId)){
											if(user.deleteTaskByRepairId(repairId)){
												Log.e("提醒>>>删除任务", repairId + "删除成功");
											}else{
												Log.e("提醒>>>删除任务", repairId + "删除失败");
											}
											
										}
										finish();
									}
								}).create().show();
				break;
			default:
				break;
			}
			super.handleMessage(msg);
		}
	};


	public static final DisplayImageOptions options = new DisplayImageOptions.Builder()
			.cacheInMemory(false) // 设置下载的图片是否缓存在内存中
			.cacheOnDisk(false).bitmapConfig(Bitmap.Config.RGB_565) // 设置下载的图片是否缓存在SD卡中
			.displayer(new RoundedBitmapDisplayer(10)) // 设置成圆角图片
			.build();

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_serviceschedule_assign);
		initData();
		initViews();
		initEvents();
		
		loginbar.setVisibility(View.VISIBLE);
		new Thread(getDataRun).start();
	}

	private void initData(){
		intent = getIntent();
		bundle = intent.getExtras();
		functioncode = bundle.getString(Config.FUNCTIONCODE);
		houseFullName = bundle.getString(Config.HOUSEFULLNAME);
		taskstate = bundle.getString(Config.TASKSTATE);
		repairId = bundle.getString(Config.REPAIRID);
		peopleType = bundle.getString(Config.PEOPLETYPE);
		statusTypeCode = bundle.getString(Config.STATUS_TYPE_CODE);
		isReporter = bundle.getBoolean(Config.ISREPORTER);
		Log.e(repairId, "repairId--111" + repairId);

		if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)
				|| functioncode.equals(Config.FUNCTION_REAL_GETPMPROGRESSLIST)
				|| functioncode
						.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)) {// 进度查看
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSDETAIL;
		} else if (functioncode
				.equals(Config.FUNCTION_REAL_GETDISPATCHTASKLIST)) {// 报修分配
			realfunctioncode = Config.FUNCTION_REAL_GETDISPATCHTASKDETAIL;
		} else if (functioncode
				.equals(Config.FUNCTION_REAL_GETREDISPATCHTASKLIST)// 改派
				|| functioncode.equals(Config.FUNCTION_REAL_OUTTIMEREPAIR)) {// 超时改派
			realfunctioncode = Config.FUNCTION_REAL_GETREDISPATCHTASKDETAIL;
		} else if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST) 
				|| functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER)) {// 维修任务、我的提单（服务人员）
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRTASKDETAIL;
		} else if (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && !peopleType.equals(Config.SERVER)) {// 我的提单
			realfunctioncode = Config.FUNCTION_REAL_GETREPAIRPROGRESSDETAIL;
		}
		
		user = SingleSample.getInstance(this).getUser();
		
		if (null != user) {
			if (null != user.getSessionId()
					&& !user.getSessionId().equals("")) {
				sessionId = user.getSessionId();
			}
		}
	}
	@Override
	protected void initViews() {
		// TODO Auto-generated method stub
		titleView = (TextView) findViewById(R.id.titlebar_left_center_title);
		titleView.setText(Config.TITLE_DOING_DETAIL);
		leftlayout = (LinearLayout) findViewById(R.id.titlebar_left_left_layout);
		loginbar = (ProgressBar) findViewById(R.id.serviceschedule_progressBar);

		sch_assign_tasknum = (TextView) findViewById(R.id.serviceschedule_assign_tasknum);
		sch_assign_address = (TextView) findViewById(R.id.serviceschedule_assign_address);
		sch_assign_object = (TextView) findViewById(R.id.serviceschedule_assign_serviceobject);
		servicechedule_timeTv = (TextView) findViewById(R.id.servicechedule_timeTv);
		sch_assign_assigntime = (TextView) findViewById(R.id.serviceschedule_assign_assignedtime);
		
		setSch_assign_reporter((TextView) findViewById(R.id.serviceschedule_assign_reporter));
		sch_assign_reporterphone = (TextView) findViewById(R.id.serviceschedule_assign_reporterphone);
		
		sch_assign_expectedtime = (TextView) findViewById(R.id.serviceschedule_str_expectedtime);
		sch_assign_reminder = (TextView) findViewById(R.id.serviceschedule_assign_reminder);
		sch_assign_serviceman = (TextView) findViewById(R.id.serviceschedule_assign_serviceman);
		sch_assign_telephone = (TextView) findViewById(R.id.serviceschedule_assign_servicetelephone);
		sch_recordtime = (TextView) findViewById(R.id.assign_repair_recordtime);
		sch_assign_describe = (TextView) findViewById(R.id.serviceschedule_assign_describe);
		tx_assign = (TextView) findViewById(R.id.str_assign);
		assign_repair_voice = (ImageView) findViewById(R.id.assign_repair_btn_voice);
		assign_repair_image1 = (ImageView) findViewById(R.id.sch_assign_imageView1);
		assign_repair_image2 = (ImageView) findViewById(R.id.sch_assign_imageView2);
		assignLineView = (View) findViewById(R.id.view_line_assign);
		assignIv = (ImageView) findViewById(R.id.iv_assign);
		repairePersonLn = (LinearLayout) findViewById(R.id.ln_repaire_person);
		guideTimelinelv = (LinearLayout) findViewById(R.id.serviceschedule_assign_guide_timeline);
		btn_accept_repair = (Button) findViewById(R.id.sch_assign_accept_repair);
		btn_start_repair = (Button) findViewById(R.id.sch_assign_start_repair);
		btn_accept_repair = (Button) findViewById(R.id.sch_assign_accept_repair);
		btn_goon_repair = (Button) findViewById(R.id.sch_assign_goon_repair);
		btn_apply_change = (Button) findViewById(R.id.sch_assign_apply_change);
		assign_repair_image1.setVisibility(View.INVISIBLE);
		assign_repair_image2.setVisibility(View.INVISIBLE);
		assign_repair_voice.setVisibility(View.INVISIBLE);
		sch_recordtime.setVisibility(View.INVISIBLE);

		btn_accept_repair.setOnClickListener(this);
		btn_start_repair.setOnClickListener(this);
		btn_goon_repair.setOnClickListener(this);
		btn_apply_change.setOnClickListener(this);
		assign_repair_image1.setOnClickListener(this);
		assign_repair_image2.setOnClickListener(this);
		assign_repair_voice.setOnClickListener(this);
		//根据任务及人员状态判断显示控件
		hideOrShowViews();
	}

	@SuppressLint("NewApi")
	@Override
	protected void initEvents() {
		// TODO Auto-generated method stub
		
		leftlayout.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		// 电话
		sch_assign_reminder.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		sch_assign_telephone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
		Log.e(functioncode, "传入的functioncode是：   "+functioncode);
		
		sch_assign_telephone.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"
						+ sch_assign_telephone.getText().toString()));
				startActivity(intent);
			}
		});
		titleView.setText(Config.TITLE_DOING_DETAIL);

		sch_assign_reminder.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

		sch_assign_telephone.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

		sch_assign_reminder.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				remindOrder();

			}

		});

	}

	@SuppressLint("NewApi")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		System.out.println("task.getTaskState()--[->22" + task.getTaskState());
		if (sureFlag) {
			taskstate = task.getTaskState();
		}
		System.out.println("task.getTaskState()--[->33" + task.getTaskState());
		if (canClick) {//canClick
			Intent i = new Intent();
			Bundle b = new Bundle();
			b.putString(Config.FUNCTIONCODE, bundle
					.get(Config.FUNCTIONCODE).toString());
			switch (v.getId()) {
			case R.id.sch_assign_accept_repair:

				uploadingdialog = new CustomLoadingDialog(
						ServiceScheduleActivity.this, "确认接单...");
				if (uploadingdialog.isShowing()) {
					uploadingdialog.dismiss();
				} else {
					uploadingdialog.show();
				}
				DemoReceiver.count--;

				new Thread(postAcceptRepairRun).start();

				break;
			case R.id.sch_assign_start_repair:
				Toast.makeText(ServiceScheduleActivity.this, "点击开始维修",
						Toast.LENGTH_SHORT).show();
				uploadingdialog = new CustomLoadingDialog(
						ServiceScheduleActivity.this, "开始维修...");
				if (uploadingdialog.isShowing()) {
					uploadingdialog.dismiss();
				} else {
					uploadingdialog.show();
				}
				new Thread(postStartRepairRun).start();
				break;
			case R.id.sch_assign_apply_change:
				Toast.makeText(ServiceScheduleActivity.this, "点击申请改派",
						Toast.LENGTH_SHORT).show();
				// 标准的对话框封装
				final CustomDialog dialog2 = new CustomDialog(
						ServiceScheduleActivity.this);

				dialog2.setTitle("申请改派");
				dialog2.setDetial("是否要申请改派？");
				dialog2.setLeftOnClick(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog2.dismiss();
					}
				});
				dialog2.show();
				dialog2.setRightOnClick(new OnClickListener() {
					@Override
					public void onClick(View v) {
						dialog2.dismiss();
						uploadingdialog = new CustomLoadingDialog(
								ServiceScheduleActivity.this, "申请改派...");
						if (uploadingdialog.isShowing()) {
							uploadingdialog.dismiss();
						} else {
							uploadingdialog.show();
						}
						new Thread(postRedispatchRun).start();
					}
				});
				dialog2.show();
				break;
			case R.id.sch_assign_goon_repair:
				b.putString(Config.FUNCTIONCODE, functioncode);
				b.putString(Config.TASKSTATE, taskstate);
				b.putString(Config.PEOPLETYPE, peopleType);
				b.putString(Config.HOUSEFULLNAME, houseFullName);
				b.putString(Config.REPAIRID, repairId);
				b.putBoolean(Config.ISREPORTER, isReporter);
				i = new Intent(ServiceScheduleActivity.this,
						ServiceScheduleAccomplishActivity.class);
				i.putExtras(b);
				startActivity(i);
				finish();
				break;
			case R.id.sch_assign_imageView1:

				Intent intent = new Intent(
						ServiceScheduleActivity.this,
						ViewPagerActivity.class);
				intent.putExtra("image1", "file://" + Config.IMAGE_PATH
						+ task.getProblemImage1());
				if (!task.getProblemImage2().equals("")) {
					intent.putExtra(
							"image2",
							"file://" + Config.IMAGE_PATH
									+ task.getProblemImage2());
				}
				startActivity(intent);

				break;
			case R.id.sch_assign_imageView2:

				Intent intent1 = new Intent(
						ServiceScheduleActivity.this,
						ViewPagerActivity.class);
				intent1.putExtra("image1", "file://"
						+ Config.IMAGE_PATH + task.getProblemImage2());
				intent1.putExtra("image2", "file://"
						+ Config.IMAGE_PATH + task.getProblemImage1());
				startActivity(intent1);

				break;
			case R.id.assign_repair_btn_voice:
				File clickfile = new File(Config.VOICE_PATH
						+ task.getProblemVoice());
				Intent it = new Intent();
				it.setAction(Intent.ACTION_VIEW);

				it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				it.putExtra("oneshot", 0);
				it.putExtra("configchange", 0);
				it.setDataAndType(
						Uri.parse("file:" + clickfile.getPath()),
						"audio/*");
				startActivity(it);
			default:
				break;
			}
			
		} else {
			showShortToast("正在加载，请稍后。。。");
		}

	}

	Runnable getDataRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			getData();
		}
	};

	// 定义发送请求的方法
	private void getData() {
		if (Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
			try {
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(realfunctioncode).get(0)
								.getFunctionUrl();
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				Log.e("getdata>>functioncode", realfunctioncode);
				map.put("functionCode", realfunctioncode);
				map.put("repairId", repairId);
				Log.e("repairId---222", repairId);
				
				result = HttpUtil.postRequestSe(url, map, sessionId);
				Log.e("任务想情的result1", result);
				String total = new JSONObject(result).getString("total");
				String messsage = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				String rows = new JSONObject(result).getString("rows");

				if (total.equals("0")) {
					/*mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "该任务不存在！")
							.sendToTarget();*/
					mHandler.obtainMessage( Config.HANDLER_MSG_GETTASK_FAIL,
							 "该任务不存在!").sendToTarget();
				} else {
					java.lang.reflect.Type type = new TypeToken<Task>() {
					}.getType();
					Gson gson = new Gson();
					JSONArray jsonArray = new JSONArray(rows);
					JSONObject jsonObject = jsonArray.getJSONObject(0);
					task = gson.fromJson(jsonObject.toString(), type);
					Log.e("task", task.getSolvedDescript()+"");
					
					task = Tool.setTaskAll(functioncode, peopleType, task,
							user);
					isReporter = Tool.isReporter(task, user.getUserId(), peopleType);
					if (flag.equals(Config.CONNECT_SUCCESS2)) {
						boolean flagb = false;
						String urlstr = Config.SERVER_URL
								+ user.getFunctionlistFromUser(
										Config.FUNCTION_REAL_DOWNLOADREPAIRFILE)
										.get(0).getFunctionUrl();
						map.put("sessionId", sessionId);
						map.put("functionCode",
								Config.FUNCTION_REAL_DOWNLOADREPAIRFILE);
						if (null != task.getProblemImage1()
								&& !task.getProblemImage1().equals("")) {
							map.put("fileName", task.getProblemImage1());
							flagb = UploadService.downFile(urlstr,
									Config.IMAGE_PATH, map);
						}
						if (null != task.getProblemImage2()
								&& !task.getProblemImage2().equals("")) {
							map.put("fileName", task.getProblemImage2());
							flagb = UploadService.downFile(urlstr,
									Config.IMAGE_PATH, map);
						}
						if (null != task.getProblemVoice()
								&& !task.getProblemVoice().equals("")) {
							map.put("fileName", task.getProblemVoice());
							flagb = UploadService.downFile(urlstr,
									Config.VOICE_PATH, map);
						}
						if (null != task.getSolvedImage1()
								&& !task.getSolvedImage1().equals("")) {
							map.put("fileName", task.getSolvedImage1());
							flagb = UploadService.downFile(urlstr,
									Config.IMAGE_PATH, map);
						}
						if (null != task.getSolvedImage2()
								&& !task.getSolvedImage2().equals("")) {
							map.put("fileName", task.getSolvedImage2());
							flagb = UploadService.downFile(urlstr,
									Config.IMAGE_PATH, map);
						}
						if (null != task.getSolvedVoice()
								&& !task.getSolvedVoice().equals("")) {
							map.put("fileName", task.getSolvedVoice());
							flagb = UploadService.downFile(urlstr,
									Config.VOICE_PATH, map);
						}
						if (flagb) {
							mHandler.obtainMessage(Config.HANDLER_MSG_SUCCESS,
									messsage).sendToTarget();// 通知主线程数据发送成功
						} else {
							mHandler.obtainMessage(Config.HANDLER_MSG_SUCCESS,
									messsage).sendToTarget();// 通知主线程数据发送成功

						}
					} else {

						mHandler.obtainMessage(Config.HANDLER_MSG_FAIL,
								messsage).sendToTarget();// 通知主线程数据发送成功

					}

				}

			} catch (Exception e) {
				Log.e("ServiceScheduleActivity", "json数据获取报错");
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "json解析出错")
						.sendToTarget();

				e.printStackTrace();
			}

		} else {

			message = "请设置网络";
			mHandler.obtainMessage(Config.HANDLER_MSG_REPAIR_START_FAIL_1,
					message).sendToTarget();

			/* start = ++refreshCnt; */
		}
	}

	// 确认接单线程
	Runnable postAcceptRepairRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			postAcceptRepair();
		}
	};

	// 请求确认接单
	private void postAcceptRepair() {
		if (Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
			try {
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(
								Config.FUNCTION_REAL_REPAIRTASKACCEPT).get(0)
								.getFunctionUrl();
				
				map.put("functionCode", Config.FUNCTION_REAL_REPAIRTASKACCEPT);
				map.put("repairId", repairId);
				
				result = HttpUtil.postRequestSe(url, map, sessionId);
				Log.e("确认接单的result", result);
				String message = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				
				if (flag.equals(Config.CONNECT_SUCCESS2)) {
					task.setStatusType_typeCode(Config.TYPECODE_SERVE);
					task.setTaskState(Config.TASKSTATE_TODO);
					System.out.println("task.getStatusType_typeCode()--->222"
							+ task.getStatusType_typeCode());
					mHandler.obtainMessage(
							Config.HANDLER_MSG_REPAIR_ACCEPT_SUCCESS, message)
							.sendToTarget();// 通知主线程数据发送成功

				} else {
					mHandler.obtainMessage(
							Config.HANDLER_MSG_REPAIR_ACCEPT_FAIL_3, "json请求失败")
							.sendToTarget();
				}

			} catch (Exception e) {
				mHandler.obtainMessage(Config.HANDLER_MSG_REPAIR_ACCEPT_FAIL_2,
						"json数据获取报错").sendToTarget();
				e.printStackTrace();
			}

		} else {

			mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
					.sendToTarget();

		}
	}

	// 开始维修线程
	Runnable postStartRepairRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			postStartRepair();
		}
	};

	// 请求开始维修
	private void postStartRepair() {
		if (Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
			try {
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(
								Config.FUNCTION_REAL_REPAIRTASKSTART).get(0)
								.getFunctionUrl();
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				map.put("functionCode", Config.FUNCTION_REAL_REPAIRTASKSTART);
				map.put("repairId", repairId);
				
				result = HttpUtil.postRequestSe(url, map, sessionId);
				Log.e("开始维修的result", result);
				String message = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				String repairTime = new JSONObject(result)
						.getString("repairTime");
				if (flag.equals(Config.CONNECT_SUCCESS2)) {
					if(user.isTaskExistByRepairId(repairId)){//存在本地保存
						Task localtask = user.getTasksByRepairId(repairId).get(0);
						long taskid = localtask.getId();
						Task savetask = new Task();
						task.setRepairTime(repairTime);
						task.setStopflag(false);
						task.setSolvedDescript(localtask.getSolvedDescript());
						task.setSolvedImage1(localtask.getSolvedImage1());
						task.setSolvedImage2(localtask.getSolvedVoice());
						savetask = task;
						savetask.setUser(user);
						savetask.save();
						user.update(user.getId());
						if(user.deleteTaskByTaskId(taskid)){
							Log.e("开始维修","repairId任务更新成功");
						}else{
							Log.e("开始维修","repairId任务更新失败");
						}
					}else{//没有本地保存
						Task savetask = new Task();
						task.setRepairTime(repairTime);
						task.setStopflag(false);
						savetask = task;
						savetask.setUser(user);
						savetask.save();
						user.update(user.getId());
					}
					
					
					mHandler.obtainMessage(
							Config.HANDLER_MSG_REPAIR_START_SUCCESS, message)
							.sendToTarget();// 通知主线程数据发送成功

				} else {
					mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, message)
							.sendToTarget();
				}

			} catch (Exception e) {
				mHandler.obtainMessage(
						Config.HANDLER_MSG_REPAIR_REDISPATCH_FAIL_1,
						"json数据获取报错").sendToTarget();
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "json数据获取报错")
						.sendToTarget();

				e.printStackTrace();
			}

		} else {
			mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
					.sendToTarget();
			Log.e("s超时", "s超时");

		}
	}

	// 申请改派线程
	Runnable postRedispatchRun = new Runnable() {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			postRedispatch();
		}
	};

	// 申请改派
	private void postRedispatch() {
		if (Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
			try {
				String result = null;
				Map<String, String> map = new HashMap<String, String>();
				String functionCodeStr = "";
				
				String url = Config.SERVER_URL
						+ user.getFunctionlistFromUser(
								Config.FUNCTION_REAL_REPAIRTASKREDISPATCHAPPLY)
								.get(0).getFunctionUrl();
				
				if (task.getStatusType_typeCode().equals(
						Config.TYPECODE_RECEIVEORDER)) {
					functionCodeStr = Config.TYPECODE_SERVERAROG;
				} else if (task.getStatusType_typeCode().equals(
						Config.TYPECODE_SERVE)
						|| task.getStatusType_typeCode().equals(
								Config.TYPECODE_REMINDE)) {
					functionCodeStr = Config.TYPECODE_SERVERAROS;
				}
				Log.e("申请改派functionCode", functionCodeStr);
				map.put("functionCode", functionCodeStr);
				map.put("repairId", repairId);
				
				result = HttpUtil.postRequestSe(url, map, sessionId);
				Log.e("申请改派的result", result);
				String message = new JSONObject(result).getString("message");
				String flag = new JSONObject(result).getString("flag");
				if (flag.equals(Config.CONNECT_SUCCESS2)) {
					mHandler.obtainMessage(
							Config.HANDLER_MSG_REPAIR_REDISPATCH_SUCCESS,
							message).sendToTarget();// 通知主线程数据发送成功

				} else {
					mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, message)
							.sendToTarget();

				}

			} catch (Exception e) {
				mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "json数据获取出错")
						.sendToTarget();

				e.printStackTrace();
			}

		} else {
			mHandler.obtainMessage(Config.HANDLER_MSG_FAIL, "请设置网络")
					.sendToTarget();
		}
	}

	private void hideOrShowViews(){
		if (functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFOWNER)
		|| functioncode
				.equals(Config.FUNCTION_REAL_GETOUTDOORPROGRESSLISTOFOWNER)
		|| functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTOFNONOWNER)

		|| functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSEVER)
		|| functioncode
				.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTMANAGER)
		|| functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER) && !isReporter	//我的提单（维修人员、非自己接单）
		) {// 进度查看
	btn_accept_repair.setVisibility(View.GONE);
	btn_start_repair.setVisibility(View.GONE);
	btn_goon_repair.setVisibility(View.GONE);
	btn_apply_change.setVisibility(View.GONE);
	if (taskstate.equals(Config.TASKSTATE_DISTRIBUTE)) {// 分配(server)
		assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
		repairePersonLn.setVisibility(View.VISIBLE);
		sch_assign_reminder.setVisibility(View.VISIBLE);
		tx_assign.setTextColor(getResources().getColor(
				R.color.nw_tx_black));
	} else if (taskstate.equals(Config.TASKSTATE_TORECEIVEORDER)) {// 待接单
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
		repairePersonLn.setVisibility(View.VISIBLE);
		btn_apply_change.setVisibility(View.VISIBLE);
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		tx_assign.setTextColor(getResources().getColor(
				R.color.nw_tx_black));
	} else if (taskstate.equals(Config.TASKSTATE_GETTASK)) {// 受理
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
	} else if (taskstate.equals(Config.TASKSTATE_DONE)) {// 完成

		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);

	} else {
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
	}
} else if (functioncode.equals(Config.FUNCTION_REAL_GETREPAIRTASKLIST)
		|| functioncode.equals(Config.FUNCTION_REAL_MYAPPLY) && peopleType.equals(Config.SERVER) && isReporter) {// 维修任务、我的提单（服务人员）

	titleView.setText(Config.TITLE_TASK_DETAIL);
	repairePersonLn.setVisibility(View.GONE);
	sch_assign_reminder.setVisibility(View.GONE);
	guideTimelinelv.setVisibility(View.GONE);
	
			if (taskstate.equals(Config.TASKSTATE_TORECEIVEORDER)) {// 待接单
				btn_accept_repair.setVisibility(View.VISIBLE);
				btn_start_repair.setVisibility(View.VISIBLE);
				btn_goon_repair.setVisibility(View.GONE);
				btn_apply_change.setVisibility(View.VISIBLE);
				btn_start_repair.setBackground(getResources().getDrawable(
						R.drawable.button_blue_press));
				btn_start_repair.setEnabled(true);
			} else if (taskstate.equals(Config.TASKSTATE_TODO)) {// 待处理
				btn_accept_repair.setVisibility(View.VISIBLE);
				btn_start_repair.setVisibility(View.VISIBLE);
				btn_goon_repair.setVisibility(View.GONE);
				btn_apply_change.setVisibility(View.VISIBLE);
				btn_accept_repair.setBackground(getResources().getDrawable(
						R.drawable.button_blue_press));
				btn_accept_repair.setEnabled(false);

			} else if (taskstate.equals(Config.TASKSTATE_DOING)
					|| taskstate.equals(Config.TASKSTATE_TOPOST)) {// 维修中、待上报
				btn_accept_repair.setVisibility(View.GONE);
				btn_start_repair.setVisibility(View.GONE);
				btn_goon_repair.setVisibility(View.VISIBLE);
				btn_apply_change.setVisibility(View.INVISIBLE);
			}else if (taskstate.equals(Config.TASKSTATE_BEASKED)) {// 被催单
				if(user.isTaskExistByRepairId(repairId)){//本地有保存
					btn_accept_repair.setVisibility(View.GONE);
					btn_start_repair.setVisibility(View.GONE);
					btn_goon_repair.setVisibility(View.VISIBLE);
					btn_apply_change.setVisibility(View.INVISIBLE);
				}else{
					btn_accept_repair.setVisibility(View.VISIBLE);
					btn_start_repair.setVisibility(View.VISIBLE);
					btn_goon_repair.setVisibility(View.GONE);
					btn_apply_change.setVisibility(View.VISIBLE);
					btn_accept_repair.setBackground(getResources().getDrawable(
							R.drawable.button_blue_press));
					btn_accept_repair.setEnabled(false);	
				}
				

			}else{//待分配
				sch_assign_reminder.setVisibility(View.INVISIBLE);
				assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
				btn_accept_repair.setVisibility(View.GONE);
				btn_start_repair.setVisibility(View.GONE);
				btn_goon_repair.setVisibility(View.GONE);
				btn_apply_change.setVisibility(View.GONE);
			}
		
} else if (functioncode
		.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTDISPACHER)) {// 派单员
	btn_accept_repair.setVisibility(View.GONE);
	btn_start_repair.setVisibility(View.GONE);
	btn_goon_repair.setVisibility(View.GONE);
	btn_apply_change.setVisibility(View.GONE);
	if (statusTypeCode.equals(Config.TYPECODE_SERVE)
			|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																// remind
		assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
		repairePersonLn.setVisibility(View.VISIBLE);
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		tx_assign.setTextColor(getResources().getColor(
				R.color.nw_tx_black));
	} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERDISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERSUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROMD)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERPROG)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
	}
} else if (functioncode.equals(Config.FUNCTION_REAL_GETPMPROGRESSLIST)) {// 进度查看-项目经理
	btn_accept_repair.setVisibility(View.GONE);
	btn_start_repair.setVisibility(View.GONE);
	btn_goon_repair.setVisibility(View.GONE);
	btn_apply_change.setVisibility(View.GONE);
	if (statusTypeCode.equals(Config.TYPECODE_SERVE)
			|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																// remind
		assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
		repairePersonLn.setVisibility(View.VISIBLE);
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		tx_assign.setTextColor(getResources().getColor(
				R.color.nw_tx_black));
	} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERDISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERSUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROMD)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERPROG)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
	}
} else if (functioncode
		.equals(Config.FUNCTION_REAL_GETREPAIRPROGRESSLISTSERVERMANAGER)) {// 进度查看-部门经理
	btn_accept_repair.setVisibility(View.GONE);
	btn_start_repair.setVisibility(View.GONE);
	btn_goon_repair.setVisibility(View.GONE);
	btn_apply_change.setVisibility(View.GONE);
	if (statusTypeCode.equals(Config.TYPECODE_SERVE)
			|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																// remind
		assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
		repairePersonLn.setVisibility(View.VISIBLE);
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		tx_assign.setTextColor(getResources().getColor(
				R.color.nw_tx_black));
	} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERDISPATCH)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERSUPERVISE)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROMD)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERPROG)
			|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
			|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)
			|| statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
		sch_assign_reminder.setVisibility(View.INVISIBLE);
		assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
	}
} else if (functioncode.equals(Config.FUNCTION_REAL_MYAPPLY)) {

	if (peopleType.equals(Config.DISPATCHER)) {
		btn_accept_repair.setVisibility(View.GONE);
		btn_start_repair.setVisibility(View.GONE);
		btn_goon_repair.setVisibility(View.GONE);
		btn_apply_change.setVisibility(View.GONE);
		if (statusTypeCode.equals(Config.TYPECODE_SERVE)
				|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																	// remind
			assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
			repairePersonLn.setVisibility(View.VISIBLE);
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			tx_assign.setTextColor(getResources().getColor(
					R.color.nw_tx_black));
		} else if (statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)) {// receiveOrder
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
		}

	} else if (peopleType.equals(Config.DEPART_DISPATCHER)) {
		btn_accept_repair.setVisibility(View.GONE);
		btn_start_repair.setVisibility(View.GONE);
		btn_goon_repair.setVisibility(View.GONE);
		btn_apply_change.setVisibility(View.GONE);
		if (statusTypeCode.equals(Config.TYPECODE_SERVE)
				|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																	// remind
			assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
			repairePersonLn.setVisibility(View.VISIBLE);
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			tx_assign.setTextColor(getResources().getColor(
					R.color.nw_tx_black));
		} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
				|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
				|| statusTypeCode
						.equals(Config.TYPECODE_MANAGERDISPATCH)
				|| statusTypeCode
						.equals(Config.TYPECODE_MANAGERSUPERVISE)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROMD)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERPROG)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROS)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)
				|| statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
		}
	} else if (peopleType.equals(Config.SERVER)) {
		if (peopleType.equals(Config.SERVER)) {
			titleView.setText(Config.TITLE_TASK_DETAIL);
			repairePersonLn.setVisibility(View.GONE);
			sch_assign_reminder.setVisibility(View.GONE);
			guideTimelinelv.setVisibility(View.GONE);
			if (bundle != null) {
				if (taskstate.equals(Config.TASKSTATE_TORECEIVEORDER)) {// 待接单
					btn_accept_repair.setVisibility(View.VISIBLE);
					btn_start_repair.setVisibility(View.VISIBLE);
					btn_goon_repair.setVisibility(View.GONE);
					btn_apply_change.setVisibility(View.VISIBLE);
					btn_start_repair.setBackground(getResources()
							.getDrawable(R.drawable.button_blue_press));
					btn_start_repair.setEnabled(true);
				} else if (taskstate.equals(Config.TASKSTATE_BEASKED)) {// 待处理
					btn_accept_repair.setVisibility(View.VISIBLE);
					btn_start_repair.setVisibility(View.VISIBLE);
					btn_goon_repair.setVisibility(View.GONE);
					btn_apply_change.setVisibility(View.VISIBLE);
					btn_accept_repair.setBackground(getResources()
							.getDrawable(R.drawable.button_blue_press));
					btn_accept_repair.setEnabled(false);

				} else if (taskstate.equals(Config.TASKSTATE_DOING)
						|| taskstate.equals(Config.TASKSTATE_TOPOST)) {// 维修中、待上报
					btn_accept_repair.setVisibility(View.GONE);
					btn_start_repair.setVisibility(View.GONE);
					btn_goon_repair.setVisibility(View.VISIBLE);
					btn_apply_change.setVisibility(View.INVISIBLE);
				}else if (taskstate.equals(Config.TASKSTATE_BEASKED)) {// 被催单
					if(user.isTaskExistByRepairId(repairId)){//本地有保存
						btn_accept_repair.setVisibility(View.GONE);
						btn_start_repair.setVisibility(View.GONE);
						btn_goon_repair.setVisibility(View.VISIBLE);
						btn_apply_change.setVisibility(View.INVISIBLE);
					}else{
						btn_accept_repair.setVisibility(View.VISIBLE);
						btn_start_repair.setVisibility(View.VISIBLE);
						btn_goon_repair.setVisibility(View.GONE);
						btn_apply_change.setVisibility(View.VISIBLE);
						btn_accept_repair.setBackground(getResources().getDrawable(
								R.drawable.button_blue_press));
						btn_accept_repair.setEnabled(false);	
					}
					

				}

			}
		} else {
			btn_accept_repair.setVisibility(View.GONE);
			btn_start_repair.setVisibility(View.GONE);
			btn_goon_repair.setVisibility(View.GONE);
			btn_apply_change.setVisibility(View.GONE);
			if (statusTypeCode.equals(Config.TYPECODE_SERVE)
					|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																		// remind
				assignLineView
						.setBackgroundResource(R.color.nw_tl_bg_red);
				assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
				repairePersonLn.setVisibility(View.VISIBLE);
				sch_assign_reminder.setVisibility(View.INVISIBLE);
				tx_assign.setTextColor(getResources().getColor(
						R.color.nw_tx_black));
			} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
					|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
					|| statusTypeCode
							.equals(Config.TYPECODE_MANAGERDISPATCH)
					|| statusTypeCode
							.equals(Config.TYPECODE_MANAGERSUPERVISE)
					|| statusTypeCode
							.equals(Config.TYPECODE_MANAGERAROMD)
					|| statusTypeCode
							.equals(Config.TYPECODE_MANAGERPROG)
					|| statusTypeCode
							.equals(Config.TYPECODE_MANAGERAROS)
					|| statusTypeCode
							.equals(Config.TYPECODE_SERVERAROG)
					|| statusTypeCode
							.equals(Config.TYPECODE_SERVERAROS)
					|| statusTypeCode
							.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
				sch_assign_reminder.setVisibility(View.INVISIBLE);
				assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
			}
		}

	} else if (peopleType.equals(Config.DEPART_MANAGER)
			|| peopleType.equals(Config.SERVER_MANAGER)) {
		btn_accept_repair.setVisibility(View.GONE);
		btn_start_repair.setVisibility(View.GONE);
		btn_goon_repair.setVisibility(View.GONE);
		btn_apply_change.setVisibility(View.GONE);
		if (statusTypeCode.equals(Config.TYPECODE_SERVE)
				|| statusTypeCode.equals(Config.TYPECODE_REMINDE)) {// serve
																	// remind
			assignLineView.setBackgroundResource(R.color.nw_tl_bg_red);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_red);
			repairePersonLn.setVisibility(View.VISIBLE);
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			tx_assign.setTextColor(getResources().getColor(
					R.color.nw_tx_black));
		} else if (statusTypeCode.equals(Config.TYPECODE_DISPATCH)
				|| statusTypeCode.equals(Config.TYPECODE_SUPERVISE)
				|| statusTypeCode
						.equals(Config.TYPECODE_MANAGERDISPATCH)
				|| statusTypeCode
						.equals(Config.TYPECODE_MANAGERSUPERVISE)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROMD)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERPROG)
				|| statusTypeCode.equals(Config.TYPECODE_MANAGERAROS)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROG)
				|| statusTypeCode.equals(Config.TYPECODE_SERVERAROS)
				|| statusTypeCode.equals(Config.TYPECODE_RECEIVEORDER)) {// receiveOrder
			sch_assign_reminder.setVisibility(View.INVISIBLE);
			assignIv.setBackgroundResource(R.drawable.timeline_assign_gray);
		}
	}
}
	}
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) { // 监控/拦截/屏蔽返回键
			finish();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	// 催单功能
	private void remindOrder() {
		// TODO Auto-generated method stub
		new AsyncTask<Void, Void, Void>() {

			private String flag;
			private String message;

			@Override
			protected void onPreExecute() {
				if (!Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
					Toast.makeText(ServiceScheduleActivity.this, "请检查网络连接！",
							Toast.LENGTH_SHORT).show();
				}
			}

			@Override
			protected Void doInBackground(Void... params) {
				if (Tool.isNetworkAvailable(ServiceScheduleActivity.this)) {
					try {
						String url = Config.SERVER_URL
								+ user.getFunctionlistFromUser(
										Config.FUNCTION_REAL_GETPROGRESSREMIND)
										.get(0).getFunctionUrl();
						Map<String, String> map = new HashMap<String, String>();
						map.put("functionCode",
								Config.FUNCTION_REAL_GETPROGRESSREMIND);
						map.put("repairId", repairId);
						
						String result = HttpUtil.postRequestSe(url, map,
								sessionId);
						Log.e("催单result", result);

						flag = new JSONObject(result).getString("flag");
						message = new JSONObject(result).getString("message");

					} catch (Exception e) {
						message = "json数据获取出错";
						e.printStackTrace();
					}

				} else {
					message = "请设置网络";
				}

				return null;
			}

			@Override
			protected void onPostExecute(Void result) {
				Toast.makeText(ServiceScheduleActivity.this, message,
						Toast.LENGTH_SHORT).show();
				if (flag.equals("success")) {
					sch_assign_reminder.setTextColor(getResources().getColor(
							R.color.nw_tx_gray));
				}

			}
		}.execute(null, null, null);
	}

	public TextView getSch_assign_reporter() {
		return sch_assign_reporter;
	}

	public void setSch_assign_reporter(TextView sch_assign_reporter) {
		this.sch_assign_reporter = sch_assign_reporter;
	}

	public static boolean notification_flag = false;

}
